package com.JZ.QM.utils;

import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.core.io.ClassPathResource;

import java.io.*;

/**
 * @author: cyc
 * @email cyc@gmail.com
 * @date: 2020/7/1 9:18
 */
public class BankAccountUtil {
    /**
     * 读取json文件
     * @return
     */
    public  static String readJson(){
        String jsonStr = "";
        try {
            InputStream inputStream= new ClassPathResource("hotLine.json").getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));            int ch = 0;
            StringBuffer sb = new StringBuffer();
            while ((ch = br.read()) != -1) {
                sb.append((char) ch);
            }
            br.close();
            jsonStr = sb.toString();
            return jsonStr;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 通过银行卡所属银行，查询对应的服务热线
     * @param bankName 所属银行名称
     * @return
     * @throws JSONException
     */
    public static String getHotLine(String bankName) throws JSONException {
        //json对象
        JSONObject json=new JSONObject(readJson());
        //银行客服电话
        Object bankPhone="";

        bankPhone=json.get(bankName);
        if (bankPhone == null){
            return "999999";
        } else {
            return bankPhone.toString();
        }
    }
}
